home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / OrganicRadioButtonUI.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  150 lines

  1. /*
  2.  * @(#)OrganicRadioButtonUI.java    1.6 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.organic;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.border.*;
  25. import com.sun.java.swing.plaf.basic.BasicRadioButtonUI;
  26.  
  27. import java.awt.*;
  28. import java.awt.event.*;
  29. import com.sun.java.swing.plaf.*;
  30.  
  31. /**
  32.  * RadioButtonUI implementation for BasicRadioButtonUI
  33.  * <p>
  34.  * Warning: serialized objects of this class will not be compatible with
  35.  * future swing releases.  The current serialization support is appropriate
  36.  * for short term storage or RMI between Swing1.0 applications.  It will
  37.  * not be possible to load serialized Swing1.0 objects with future releases
  38.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  39.  * baseline for the serialized form of Swing objects.
  40.  *
  41.  * @version 1.6 02/02/98
  42.  * @author Tom Santos
  43.  */
  44. public class OrganicRadioButtonUI extends BasicRadioButtonUI {
  45.  
  46.     private static final OrganicRadioButtonUI organicRadioButtonUI = new OrganicRadioButtonUI();
  47.  
  48.     public static ComponentUI createUI(JComponent c) {
  49.         return organicRadioButtonUI;
  50.     }
  51.     
  52.     // Inherited instance vars
  53.     //
  54.     // protected static ButtonUI radioButtonUI;
  55.     // protected Icon icon;
  56.     
  57.     /************************** The View *************************/
  58.  
  59.     protected ButtonModel model;
  60.  
  61.     /**
  62.      * paint the radio button
  63.      */
  64.     public synchronized void paint(Graphics g, JComponent c) {
  65.  
  66.     AbstractButton b = (AbstractButton) c;
  67.     model = b.getModel();
  68.     
  69.     Dimension size = c.getSize();
  70.  
  71.     int w = size.width;
  72.     int h = size.height;
  73.  
  74.     Font f = c.getFont();
  75.     g.setFont(f);
  76.     FontMetrics fm = g.getFontMetrics();
  77.  
  78.     Rectangle viewRect = new Rectangle(size);
  79.         Rectangle iconRect = new Rectangle();
  80.         Rectangle textRect = new Rectangle();
  81.  
  82.     Icon altIcon = b.getIcon();
  83.     Icon selectedIcon = null;
  84.     Icon disabledIcon = null;
  85.     
  86.         String text = SwingUtilities.layoutCompoundLabel(
  87.             fm, b.getText(), altIcon != null ? altIcon : icon,
  88.             b.getVerticalAlignment(), b.getHorizontalAlignment(),
  89.             b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
  90.             viewRect, iconRect, textRect, getDefaultTextIconGap(b)
  91.         );
  92.     
  93.         g.setColor( b.getBackground() );
  94.  
  95.     if ( b.isOpaque() ) {  
  96.         g.fillRect(0,0, size.width, size.height); 
  97.     }
  98.  
  99.     
  100.     // Paint the radio button
  101.         if(altIcon != null) { 
  102.  
  103.             if(!model.isEnabled()) {
  104.                 altIcon = b.getDisabledIcon();
  105.             } else if(model.isPressed() && model.isArmed()) {
  106.                 altIcon = b.getPressedIcon();
  107.                 if(altIcon == null) {
  108.                     // Use selected icon
  109.                     altIcon = b.getSelectedIcon();
  110.                 } 
  111.             } else if(model.isSelected()) {
  112.                 altIcon = b.getSelectedIcon();
  113.             } 
  114.           
  115.         if(altIcon == null) {
  116.         altIcon = b.getIcon();
  117.         }
  118.            
  119.         altIcon.paintIcon(c, g, iconRect.x, iconRect.y);
  120.  
  121.         } else {
  122.         icon.paintIcon(c, g, iconRect.x, iconRect.y);
  123.     }
  124.  
  125.  
  126.     // Draw the Text
  127.     if(text != null) {
  128.         if(!model.isEnabled()) {
  129.         g.setColor( UIManager.getColor("RadioButton.darkShadow") );
  130.         } else {
  131.         g.setColor(b.getForeground());
  132.         }
  133.  
  134.         OrganicUtilities.drawString(g,text,model.getMnemonic(),
  135.                     textRect.x, textRect.y + fm.getAscent());
  136.  
  137.             if(b.hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0 ) {
  138.             g.setColor( UIManager.getColor("RadioButton.highlight") );
  139.         g.drawRect( textRect.x-1,textRect.y-1,
  140.                 textRect.width+1,textRect.height+1);
  141.                 g.setColor(UIManager.getColor("RadioButton.focus"));
  142.                 OrganicUtilities.drawDashedRect(g,textRect.x-1,textRect.y-1,
  143.                                                   textRect.width+2,textRect.height+2);
  144.             }
  145.     }
  146.     }
  147.  
  148.  
  149. }
  150.